


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">



<?php require_once 'db.php'; ?>
<link rel="stylesheet" type="text/css" href="../css/cssMode.css"> 

<?php 
    $query = "SELECT * FROM companies";
    $companies = getData($query);
  $query = "SELECT * FROM apps";
 
     $apps = getData($query);?>

<form action="pages.php" method="post"  class="form-wrapper">
    <h1> VO Tuan Anh </h1>
     <p> SEARCH</p>
     
      <center><table>
            <tr> <td><input type="text" name="min" placeholder="min" id="value"></td> </tr>
            <tr> <td><input type="text" name="max" placeholder="max" id="value" ></td></tr>
            <tr><td><input type="text" name="keyword" id="values" id="value" placeholder="keyword" ></td></tr>
            <tr><td>  Company<select name="id_company">
            <?php foreach ($companies as $company): ?>
                        <option  value="<?php echo $company['id'] ?>"><?php echo $company['name']?></option>
    <?php  endforeach;?>
    </select></td></tr>
            
    <!--dfsdffffffffffffffffffffffffffffff-->
    <!-- aappppppppppp -->
    
    <tr><td>        
       App..........<select name="id_apps">
      <?php foreach ($apps as $app): ?>
       <option value="<?php echo $app['id'] ?>"><?php echo $app['name']?></option>
       <?php  endforeach;?>
    </select></td></tr>
    
    
           <tr><td><input type="submit" name="submit" value="search"  id="submit" ></td></tr>
            <!-- the end search max min -->
     
            <!-- begin search table -->

            
<!--             <tr><td><select id="search_by">
                    <option value="id" id="right">name</option>
                    <option value="name">username</option>
              </select></td></tr>
             
             <tr><td><select id="search_by">
                   <option value="id">likes</option>
                   <option value="name">links</option>
             </select></td></tr>
             
             
             <tr><td><select id="search_by">
                   <option value="id">url</option>
                   <option value="name">website</option>
             </select></td> </tr>
             
             <tr><td><select id="search_by">
                  <option value="id">street</option>
                  <option value="id" id="right">description</option>
                  <option value="id" id="right">about</option>
                  <option value="name">city</option>
            </select></td> </tr>
             
  -->
</table>
</center>
</form>
<!-- the end select -->



<?php if (isset($_POST['submit'])): ?>

    <?php
    $min = $_POST['min'];
    $max =  $_POST['max'];
    $keyword = $_POST['keyword'];
     if (empty($keyword)) {
        if (empty($max) && empty($min)) {
            $query = "SELECT * FROM pages 
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        } elseif (empty($max)) {
            $query = "SELECT * FROM pages 
                  WHERE (likes >= $min)
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        } elseif (empty($min)) {
            $query = "SELECT * FROM pages 
                  WHERE (likes <= $max)
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        } else {
            $query = "SELECT * FROM pages 
                  WHERE (likes <= $max)
                  AND  (likes >= $min)
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        }
    } else {
        if (empty($max) && empty($min)) {
            $query = "SELECT * FROM pages WHERE
                  (description LIKE '% $keyword %')
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        } elseif (empty($max)) {
            $query = "SELECT * FROM pages WHERE
                  (description LIKE '% $keyword %')
                  AND  (likes >= $min)
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        } elseif (empty($min)) {
            $query = "SELECT * FROM pages WHERE
                  (description LIKE '% $keyword %')
                  AND  (likes <= $max)
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        } else {
            $query = "SELECT * FROM pages
                  
                      WHERE (description LIKE '% $keyword %') 
                      AND(likes >= $min)
                      AND (likes <= $max)
                  LIMIT 0, 10
                  ";
            $pages = getData($query);
        }
    }
    
     

     $pages = getData($query);?>


<?php var_dump($query) ; ?>

<?php if (!empty($pages)):?>


<table border="1" style="border: 1px solid #3366ff;">
       <tr>
       
       <td style="background: #99ff99; text-align: center;">pid</td>   
       <td style="background: #99ff99; text-align: center;">id</td>
       <td style="background: #99ff99; text-align: center;">name</td>
       <td style="background: #99ff99; text-align: center;">username</td>
       <td style="background: #99ff99; text-align: center;">likes</td>
       <td style="background: #99ff99; text-align: center;">piture</td>
       <td style="background: #99ff99; text-align: center;">description</td>
       <td style="background: #99ff99; text-align: center;">about</td>
      
       </tr>

      <!--keyword -->
      <?php foreach ($pages as $page): ?>
 
           <tr>
               <td><?php echo $page['pid'] ?></td>
               <td><?php echo $page['id'] ?></td>
               <td><?php echo $page['name'] ?></td>
               <td><?php echo $page['username'] ?></td>
               <td><?php echo $page['likes'] ?></td>
               <td>  <img src="<?php echo $page['picture'] ?>"></td>
               <td><?php echo substr($page['description'] ,0,100) ?></td>
               <td><?php echo $page['about'] ?></td>
                
              </tr>
 
            <?php endforeach; ?>
            </table>
<?php endif; ?>
<?php endif; ?>